package cn.whpu.omnitrixerp.controller.auth;


import cn.whpu.omnitrixerp.common.Result;
import cn.whpu.omnitrixerp.entity.dto.auth.LoginReqDTO;
import cn.whpu.omnitrixerp.entity.dto.auth.LoginRespDTO;
import cn.whpu.omnitrixerp.entity.dto.auth.UserDTO;
import cn.whpu.omnitrixerp.service.auth.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gim Gong
 * @date 2025/6/29
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Result<LoginRespDTO> login(@RequestBody LoginReqDTO loginReqDTO) {
        return Result.success(userService.login(loginReqDTO));
    }

    @PostMapping("/add")
    public Result<String> add(@RequestBody UserDTO userDTO) {
        userService.add(userDTO);
        return Result.success();
    }

    @PostMapping("/edit")
    public Result<String> edit(@RequestBody UserDTO userDTO) {
        userService.edit(userDTO);
        return Result.success();
    }

    @PostMapping("/delete")
    public Result<String> delete(List<Integer> idList) {
        userService.delete(idList);
        return Result.success();
    }
}
